﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace RestaurantWebService
{
    public class OccupancyManager
    {
        private const string occupySql = "REPLACE INTO occupancy(tableNumber, seatNumber, occupied) VALUES({0}, {1}, {2})";
        private const string getOccupancySql = "SELECT occupied FROM occupancy WHERE tableNumber = {0} AND seatNumber = {1}";

        private DatabaseManager dbManager;

        public OccupancyManager()
        {
            dbManager = new DatabaseManager();
        }

        public void markTableOccupancy(int table, bool occupied)
        {
            dbManager.executeNonQuery(String.Format(occupySql, table, null, occupied ? 1 : 0));
        }

        public bool getTableOccupancy(int table)
        {
            int occupied = (int) dbManager.executeScalar(String.Format(getOccupancySql, table, null));
            return occupied == 1 ? true : false;
        }

        public void markChairOccupancy(int table, int chair, bool occupied)
        {
            dbManager.executeNonQuery(String.Format(occupySql, table, chair, occupied ? 1 : 0));
        }

        public bool getChariOccupancy(int table, int chair)
        {
            int occupied = (int) dbManager.executeScalar(String.Format(getOccupancySql, table, chair));
            return occupied == 1 ? true : false;
        }
    }
}